package hy.service;

import hy.beans.Account;
import hy.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountServiceImpl {
	@Autowired
	AccountDao dao;

	public void a(String from, String to, Double money){
		this.transfer(from,to,money);
	}

	@Transactional(isolation = Isolation.SERIALIZABLE,rollbackFor = Exception.class,readOnly = false,timeout = 5)
	public void transfer(String from, String to, Double money) {
			dao.update(from, 0 - money);
			dao.update(to, money);
	}

	
	public void query(String name) {
		System.out.println(name+"的余额："+dao.selectMoney(name));
	}

	
	public void insert() {
		System.out.println(dao.insert(new Account(null,"a3",500.0)));
	}
}